package com.heima.user.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.LoginDto;
import com.heima.model.user.vo.ApUserVo;
import com.heima.user.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/login")
public class AppUserController {
    @Autowired
    private AppUserService appUserService;
    @PostMapping("/login_auth")
    public ResponseResult<ApUserVo> login(@RequestBody(required = false) LoginDto dto){
        ApUserVo userVo = appUserService.login(dto);
        if (userVo==null){
            return ResponseResult.errorResult(401,"用户名或密码错误");
        }
        return ResponseResult.okResult(userVo);
    }
}
